package com.erlang.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "sonMapping")
public class SonMappingController {

    @GetMapping
    public ModelAndView get(){
        //构建对象视图对象
        ModelAndView modelAndView = new ModelAndView();
        //指定视图
        modelAndView.setViewName("succeed");
        //传递参数，接受map对象
        Map<String,Object> map = new HashMap<>();
        map.put("content", "get");
        modelAndView.addAllObjects(map);
        return modelAndView;
    }

    @PostMapping
    public ModelAndView post(){
        //构建对象视图对象
        ModelAndView modelAndView = new ModelAndView();
        //指定视图
        modelAndView.setViewName("succeed");
        //传递参数，接受map对象
        Map<String,Object> map = new HashMap<>();
        map.put("content", "post");
        modelAndView.addAllObjects(map);
        return modelAndView;
    }

    @PutMapping
    public ModelAndView put(){
        //构建对象视图对象
        ModelAndView modelAndView = new ModelAndView();
        //指定视图
        modelAndView.setViewName("succeed");
        //传递参数，接受map对象
        Map<String,Object> map = new HashMap<>();
        map.put("content", "put");
        modelAndView.addAllObjects(map);
        return modelAndView;
    }

    @DeleteMapping
    public ModelAndView delete(){
        //构建对象视图对象
        ModelAndView modelAndView = new ModelAndView();
        //指定视图
        modelAndView.setViewName("succeed");
        //传递参数，接受map对象
        Map<String,Object> map = new HashMap<>();
        map.put("content", "delete");
        modelAndView.addAllObjects(map);
        return modelAndView;
    }

    @PatchMapping
    public ModelAndView patch(){
        //构建对象视图对象
        ModelAndView modelAndView = new ModelAndView();
        //指定视图
        modelAndView.setViewName("succeed");
        //传递参数，接受map对象
        Map<String,Object> map = new HashMap<>();
        map.put("content", "patch");
        modelAndView.addAllObjects(map);
        return modelAndView;
    }
}

